package office.action.business;

import java.util.List;

import office.action.business.form.StorageConditionForm;
import office.action.business.form.StorageForm;
import office.action.business.form.SupplierConditionForm;
import office.action.business.wrapper.StorageWrapper;
import office.action.business.wrapper.SupplierWrapper;
import office.service.business.IStorageService;
import office.service.business.ISupplierService;
import platform.common.action.BaseAction;
import platform.common.bo.Page;

/**
 * 
 * 产品明细
 * 
 * @author ZhangYQ
 * 
 */
public class StorageAction extends BaseAction {
	private static final long serialVersionUID = 1L;
	private IStorageService storageService;
	private ISupplierService supplierService;
	private Page page; // 分页信息
	private List<StorageWrapper> wrapperList;
	private List<SupplierWrapper> supplierWrapperList;
	private StorageForm form;
	private StorageConditionForm condition;
	private SupplierConditionForm supplierCondition;
	private String id;
	
	/**
	 * 获取所有的产品明细以及根据条件进行查询
	 * 
	 * @return
	 * @throws Exception
	 */
	public String findAllStorage() throws Exception {
		page = storageService.getPageInfo(condition);
		wrapperList = storageService.findAllStorage(condition,page);
		if(condition!=null){
			return "listStorageByPage";
		}
		return "findAllStorage";
	}

	/**
	 * 初始化编辑产品明细页面
	 * @return
	 * @throws Exception
	 */
	public String gotoEditStorage() throws Exception {
		supplierWrapperList=supplierService.findAllSupplier(supplierCondition, null);
		if(null!=id&&!"".equals(id)){
			form = storageService.getById(id);
		}
		return "gotoEditStorage";
	}

	/**
	 * 编辑产品明细
	 * 
	 * @return
	 * @throws Exception
	 */
	public String editStorage() throws Exception {
		try {
			//获取当前用户
			String userId=(String) getUserMap().get("userId");
			form.setIntoMan(userId);
			storageService.editStorage(form);
			if (null == form.getId()
					|| ("").equals(form.getId())) {
				this.getAjaxMessagesJson().setMessage(true, "", "新建成功");
			} else {
				this.getAjaxMessagesJson().setMessage(true, "", "编辑成功");
			}

		} catch (Exception e) {
			this.handleException(e);
		}
		return RESULT_AJAXJSON;
	}

	/**
	 * 
	 * <br/>
	 * 方法描述:分页条件查询产品结构
	 * 
	 * @return
	 * @throws Exception
	 */
	public String listStorageByPage() throws Exception {
		try {
			wrapperList = storageService.findAllStorage(condition, page);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			throw e;
		}
		return "listStorageByPage";
	}

	/**
	 * 初始化产品结构列表操作菜单
	 * 
	 * @return
	 * @throws Exception
	 */

	public String gotoStorageMenu() throws Exception {
		return "gotoStorageMenu";
	}

	/**
	 * 跳转到产品明细删除确认页面
	 */
	public String gotoDeleteStorage(){
		return "gotoDeleteStorage";
	}
	
	/**
	 * 删除产品明细
	 * @return
	 * @throws Exception
	 */
	public String delStorage() throws Exception {
		try {
			storageService.delStorageById(id);
			this.getAjaxMessagesJson().setMessage(true, "", "操作成功");
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			throw e;
		}
		return RESULT_AJAXJSON;
	}

	public IStorageService getStorageService() {
		return storageService;
	}

	public void setStorageService(IStorageService storageService) {
		this.storageService = storageService;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	public List<StorageWrapper> getWrapperList() {
		return wrapperList;
	}

	public void setWrapperList(List<StorageWrapper> wrapperList) {
		this.wrapperList = wrapperList;
	}

	public StorageForm getForm() {
		return form;
	}

	public void setForm(StorageForm form) {
		this.form = form;
	}

	public StorageConditionForm getCondition() {
		return condition;
	}

	public void setCondition(StorageConditionForm condition) {
		this.condition = condition;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public List<SupplierWrapper> getSupplierWrapperList() {
		return supplierWrapperList;
	}

	public void setSupplierWrapperList(List<SupplierWrapper> supplierWrapperList) {
		this.supplierWrapperList = supplierWrapperList;
	}

	public ISupplierService getSupplierService() {
		return supplierService;
	}

	public void setSupplierService(ISupplierService supplierService) {
		this.supplierService = supplierService;
	}

	public SupplierConditionForm getSupplierCondition() {
		return supplierCondition;
	}

	public void setSupplierCondition(SupplierConditionForm supplierCondition) {
		this.supplierCondition = supplierCondition;
	}
	
}
